package middleware

import (
	"github.com/gogf/gf/v2/net/ghttp"
	"github.com/gogf/gf/v2/util/guid"
)

// MiddlewareHandlerResponse is the default middleware handling handler response object and its error.
func MiddlewareReqId(r *ghttp.Request) {
	reqId := r.Header.Get("reqid")
	if reqId == "" {
		reqId = "rq" + guid.S()
		r.Header.Set("reqid", reqId)
	}

	r.Middleware.Next()

	r.Response.Header().Set("reqid", reqId)
}
